var plot = {
  headHeightFactor: 0.15, // 0.2,
  headWidthFactor: 0.3, // 0.5,
  neckHeightFactor: 0.75, // 0.8,
  neckWidthFactor: 0.2,
  tailWidthFactor: 0.1,
  hasSwallowTail: true,
  swallowTailFactor: 0.5,
  curveFitMethod: 'useBSplieFit',
  maxVertices: 20
}
/** Method:setParams
 * 设置箭头参数
 */
plot.setParams = function (iOptions) {
  if (iOptions) {
    /**
    * Property: headHeightFactor
    * {Number} 箭头头部高度因子
    */
    this.headHeightFactor = iOptions.headHeightFactor ? iOptions.headHeightFactor : 0.2

    /**
    * Property: headHeightFactor
    * {Number} 箭头头部宽度因子
    */
    this.headWidthFactor = iOptions.headWidthFactor ? iOptions.headWidthFactor : 0.5

    /**
    * Property: headHeightFactor
    * {Number} 箭头腰部高度因子
    */
    this.neckHeightFactor = iOptions.neckHeightFactor ? iOptions.neckHeightFactor : 0.8

    /**
    * Property: headHeightFactor
    * {Number} 箭头腰部宽度因子
    */
    this.neckWidthFactor = iOptions.neckWidthFactor ? iOptions.neckWidthFactor : 0.2

    /**
    * Property: headHeightFactor
    * {Number} 箭头尾部宽度因子
    */
    this.tailWidthFactor = iOptions.tailWidthFactor ? iOptions.tailWidthFactor : 0.1

    this.hasSwallowTail = iOptions.hasSwallowTail ? iOptions.hasSwallowTail : true
    this.swallowTailFactor = iOptions.swallowTailFactor ? iOptions.swallowTailFactor : 0.5
    this.curveFitMethod = iOptions.curveFitMethod ? iOptions.curveFitMethod : 'useBSplieFit'
    this.maxVertices = iOptions.maxVertices ? iOptions.maxVertices : 20 // 最大控制点数
  }
}

/** Method:CalLengthOfTwoPoints
 * 计算两个点长度
 */
plot.CalLengthOfTwoPoints = function (p1, p2) {
  let len = 0
  len = Math.sqrt(Math.pow((p1[0] - p2[0]), 2) + Math.pow((p1[1] - p2[1]), 2))
  return len
}

/** Method:wholeDistance
 * 计算整个箭头长度
 */
plot.wholeDistance = function (arrDots) {
  var len = 0
  // 箭头点不为空 且 点个数 > 1;
  if (arrDots != null && arrDots.length > 1) {
    for (var i = 0; i < arrDots.length - 1; i++) {
      len += plot.CalLengthOfTwoPoints(arrDots[i], arrDots[i + 1])
    }
  }
  return len
}

/** Method:getLineAngle
 * 获取两条线的角度
 */
plot.getLineAngle = function (geoPntStart, geoPntEnd) {
  let angle = Math.atan2(geoPntEnd[1] - geoPntStart[1], geoPntEnd[0] - geoPntStart[0]) // * 180 / Math.PI;
  // 取值从-π到π，逆时针为正；+π，角度从0到2π
  angle = angle + Math.PI
  return angle
}

// 获取角度
plot.getAzimuthAngle = function (startPoint, endPoint) {
  let azimuth = 0
  const angle = Math.asin(Math.abs(endPoint[1] - startPoint[1]) / plot.CalLengthOfTwoPoints(startPoint, endPoint))
  if (endPoint[1] >= startPoint[1] && endPoint[0] >= startPoint[0]) {
    azimuth = angle + Math.PI
  } else if (endPoint[1] >= startPoint[1] && endPoint[0] < startPoint[0]) {
    azimuth = Math.PI * 2 - angle
  } else if (endPoint[1] < startPoint[1] && endPoint[0] < startPoint[0]) {
    azimuth = angle
  } else if (endPoint[1] < startPoint[1] && endPoint[0] >= startPoint[0]) {
    azimuth = Math.PI - angle
  }
  return azimuth
}
// 确定是否为顺时针方向
plot.isClockWise = function (pnt1, pnt2, pnt3) {
  return (pnt3[1] - pnt1[1]) * (pnt2[0] - pnt1[0]) > (pnt2[1] - pnt1[1]) * (pnt3[0] - pnt1[0])
}
/** Method:getThirdPoint
 * 获取箭头左、右箭头点
 */
plot.getThirdPoint = function (startPnt, endPnt, angle, length, side) {
  // var num = getAzimuthAngle(startPnt, endPnt);
  // 获取角度--开始和结束点的角度（0到2π）
  var num = plot.getLineAngle(startPnt, endPnt)
  var num2 = 0.0
  if (side.toLowerCase() === 'left') {
    num2 = num + angle
  } else {
    num2 = num - angle
  }
  const num3 = length * Math.cos(num2)
  const num4 = length * Math.sin(num2)
  return [endPnt[0] + num3, endPnt[1] + num4]
}

/** Method:getAngleOfThreePoints
 * 根据三个点获取角度
 */
plot.getAngleOfThreePoints = function (pntA, pntB, pntC) {
  const n1 = plot.getLineAngle(pntB, pntA)
  const n2 = plot.getLineAngle(pntB, pntC)
  let num = n1 - n2
  // console.log('TP：' + num + ' : ' + num*180/Math.PI);
  if (num < 0.0) {
    num += 2 * Math.PI
  }
  // console.log('TP2：' + num + ' : ' + num*180/Math.PI);
  return num
}

/** Method:getArrowHeadPoints
 * 获取箭头顶点
 * 参数points：绘制箭头的控制点, headHeightFactor, headWidthFactor箭头头部宽度因子, neckHeightFactor箭头腰部高度因子, neckWidthFactor箭头腰部宽度因子
 * 返回：构成箭头的五个点--数组
 */
plot.getArrowHeadPoints = function (points, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor) {
  const num = points.length
  if (num < 2) {
    return points
  }
  let length = plot.wholeDistance(points) * headHeightFactor // 获取整个箭头长度 * 箭头长度因子（1/4,1/5）
  const num3 = length * headWidthFactor // 获取箭头宽度
  const num4 = length * neckWidthFactor // 获取箭头颈部宽度
  const num5 = points.length // 箭头控制点数

  const point = [points[num5 - 1][0], points[num5 - 1][1]] // 获取夹头的最后一个点
  const num6 = plot.CalLengthOfTwoPoints(point, points[num5 - 2]) // 计算最后两个点长度
  length = (length > num6) ? num6 : length // 确定箭头长度
  const num7 = length * neckHeightFactor // 箭头颈高
  const endPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, length, 'left') // 箭头长点，在最后两点位置上
  const point3 = plot.getThirdPoint(points[num5 - 2], point, 0.0, num7, 'left') // 箭头颈长点
  const point4 = plot.getThirdPoint(point, endPnt, 30, num3, 'right') // 以下计算夹头点
  const point5 = plot.getThirdPoint(point, point3, 30, num4, 'right')
  const point6 = plot.getThirdPoint(point, endPnt, 30, num3, 'left')
  const point7 = plot.getThirdPoint(point, point3, 30, num4, 'left')
  const listHead = [] // new Array()
  listHead.push(point5)
  listHead.push(point4)
  listHead.push(point)
  listHead.push(point6)
  listHead.push(point7)

  return listHead
}

/** Method:getArrowHeadPointsForSLine
 * 获取简单线箭头顶点
 * 参数points：绘制箭头的控制点, headHeightFactor, headWidthFactor箭头头部宽度因子
 * 返回：构成箭头的数组，需要构成多边形
 */
// plot.getArrowHeadPointsForSLine = function (points, headHeightFactor, headWidthFactor) {
//   if (points.length < 2) {
//     return points
//   }

//   let length = plot.CalLengthOfTwoPoints(points[0], points[1]) * headHeightFactor // 获取箭头长度
//   let num3 = length * headWidthFactor // 获取箭头宽度
//   let num5 = points.length

//   let point = points[num5 - 1]
//   let num6 = plot.CalLengthOfTwoPoints(point, points[num5 - 2])
//   length = (length > num6) ? num6 : length

//   let endPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, length, 'left')
//   let point4 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'right')
//   let point6 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'left')

//   let listHead = [] // new Array()

//   listHead.push(point4)
//   listHead.push(point)
//   listHead.push(point6)

//   return listHead
// }
// 为mybox平台plus调整（返回简单线条箭头）--Mbox后加的
plot.getArrowHeadPointsForSLineMbox = function (points, headHeightFactor, headWidthFactor) {
  if (points.length < 2) {
    return points
  }

  let length = plot.CalLengthOfTwoPoints(points[0], points[1]) * headHeightFactor // 获取箭头长度
  const num3 = length * headWidthFactor // 获取箭头宽度
  const num5 = points.length

  const point = points[num5 - 1]
  const num6 = plot.CalLengthOfTwoPoints(point, points[num5 - 2])
  length = (length > num6) ? num6 : length

  const endPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, length, 'left')
  const point4 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'right')
  const point6 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'left')

  return { type: 'LineString', pntLs: [point4, point, point6] }
}

// 最新为ol环境调整（返回箭头线数据点）
plot.getArrowHeadPointsForSLine = function (points, headHeightFactor, headWidthFactor) {
  if (points.length < 2) {
    // return points
    return null
  }

  let length = plot.CalLengthOfTwoPoints(points[0], points[1]) * headHeightFactor // 获取箭头长度
  const num3 = length * headWidthFactor // 获取箭头宽度
  const num5 = points.length

  const point = points[num5 - 1]
  const num6 = plot.CalLengthOfTwoPoints(point, points[num5 - 2])
  length = (length > num6) ? num6 : length

  const endPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, length, 'left')
  const point4 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'right')
  const point6 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'left')

  return { type: 'LineString', data: [point4, point, point6] }
}

// ol-new 返回polygon箭头对象（返回多边形对象的箭头）
plot.getArrowHeadPointsForSLine2 = function (points, headHeightFactor, headWidthFactor, neckHeightFactor) {
  if (points.length < 2) {
    // return points
    return null
  }

  let length = plot.CalLengthOfTwoPoints(points[0], points[1]) * headHeightFactor // 获取箭头长度（前两点）
  const num3 = length * headWidthFactor // 获取箭头宽度
  const num5 = points.length

  const point = points[num5 - 1]
  const num6 = plot.CalLengthOfTwoPoints(point, points[num5 - 2]) // 后两个点长度
  length = (length > num6) ? num6 : length // 使用较短的一个长度
  const neckLength = length * neckHeightFactor

  const endPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, length, 'left')
  const point4 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'right')
  const point6 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'left')
  // 获取箭头颈高
  const neckPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, neckLength, 'left')
  // console.log(neckPnt)

  // let listHead = [] // new Array()

  // listHead.push(neckPnt)
  // listHead.push(point4)
  // listHead.push(point)
  // listHead.push(point6)
  // listHead.push(neckPnt)
  // return listHead
  // return { type: 'Polygon', pntLs: [neckPnt, point4, point, point6, neckPnt] }
  // console.log(neckPnt, point4, point, point6, neckPnt)
  return { type: 'Polygon', data: [[neckPnt, point4, point, point6, neckPnt]] }
}
// ol-new 返回polygon箭头对象（返回多边形对象的箭头）
plot.getArrowHeadPointsForSLine3 = function (points, headHeightFactor, headWidthFactor, neckHeightFactor) {
  if (points.length < 2) {
    // return points
    return null
  }

  // let length = plot.CalLengthOfTwoPoints(points[0], points[1]) * headHeightFactor // 获取箭头长度（前两点）
  let length = plot.wholeDistance(points) * 0.05
  const num3 = length * headWidthFactor // 获取箭头宽度
  const num5 = points.length

  const point = points[num5 - 1]
  const num6 = plot.CalLengthOfTwoPoints(point, points[num5 - 2]) // 后两个点长度
  length = (length > num6) ? num6 : length // 使用较短的一个长度
  const neckLength = length * neckHeightFactor

  const endPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, length, 'left')
  const point4 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'right')
  const point6 = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num3, 'left')
  // 获取箭头颈高
  const neckPnt = plot.getThirdPoint(points[num5 - 2], point, 0.0, neckLength, 'left')
  // console.log(neckPnt)

  // let listHead = [] // new Array()

  // listHead.push(neckPnt)
  // listHead.push(point4)
  // listHead.push(point)
  // listHead.push(point6)
  // listHead.push(neckPnt)
  // return listHead
  // return { type: 'Polygon', pntLs: [neckPnt, point4, point, point6, neckPnt] }
  // console.log(neckPnt, point4, point, point6, neckPnt)
  return { type: 'Polygon', data: [[neckPnt, point4, point, point6, neckPnt]] }
}

// 求n!
plot.getFactorial = function (n) {
  let num = 1
  for (var i = 1; i <= n; i++) {
    num *= i
  }
  return num
}

plot.getQuadricBSplineFactor = function (k, t) {
  if (k === 0) {
    return (Math.pow((t - 1.0), 2.0) / 2.0)
  }
  if (k === 1) {
    return ((((-2.0 * Math.pow(t, 2.0)) + (2.0 * t)) + 1.0) / 2.0)
  }
  if (k === 2) {
    return (Math.pow(t, 2.0) / 2.0)
  }
  return 0.0
}

plot.getBinomialFactor = function (n, index) {
  let num = 0.0
  num = plot.getFactorial(n) / (plot.getFactorial(index) * plot.getFactorial(n - index))
  return num
}

plot.getBSplineFFactor = function (k, n, t) {
  if (n === 2) {
    return plot.getQuadricBSplineFactor(k, t)
  }
  let num = 0.0
  const num2 = plot.getFactorial(n)
  for (var i = 0; i <= (n - k); i++) {
    var num4 = ((i % 2) === 0) ? 1 : -1
    num += (num4 * plot.getBinomialFactor(n + 1, i)) * Math.pow(((t + n) - k) - i, n)
  }
  return (num / num2)
}

plot.getBSplinePoints = function (points, n) {
  if ((points.length <= 2) || (points.length <= n)) {
    return points
  }
  const list = [] // new Array()
  const num = (points.length - n) - 1
  list.push(points[0])
  for (var i = 0; i <= num; i++) {
    // for (var j = 0.0; j <= 1.0; j += 0.1) {
    for (var j = 0.0; j <= 1.0; j += 0.05) {
      var x = 0.0
      let y = 0.0
      for (var k = 0; k <= n; k++) {
        const num7 = plot.getBSplineFFactor(k, n, j)
        x += num7 * points[i + k][0]
        y += num7 * points[i + k][1]
      }
      list.push([x, y])
    }
  }
  list.push(points[points.length - 1])
  return list
}
// 为mb标会的plus提供支持
plot.getBSplinePointsPlus = function (points, n) {
  if ((points.length <= 2) || (points.length <= n)) {
    return points
  }
  const list = [] // new Array()
  const num = (points.length - n) - 1
  list.push(points[0])
  for (var i = 0; i <= num; i++) {
    // for (var j = 0.0; j <= 1.0; j += 0.1) {
    for (var j = 0.0; j <= 1.0; j += 0.05) {
      var x = 0.0
      let y = 0.0
      for (var k = 0; k <= n; k++) {
        const num7 = plot.getBSplineFFactor(k, n, j)
        x += num7 * points[i + k][0]
        y += num7 * points[i + k][1]
      }
      list.push([x, y])
    }
  }
  list.push(points[points.length - 1])
  // return list
  return { type: 'LineString', pntLs: list }
}

plot.getBezierPoints = function (points) {
  if (points.length <= 2) {
    return points
  }
  const list = [] // new Array()
  const n = points.length - 1
  for (var i = 0.0; i <= 1.0; i += 0.01) {
    var x = 0.0
    var y = 0.0
    for (var j = 0; j <= n; j++) {
      var num6 = plot.getBinomialFactor(n, j)
      var num7 = Math.pow(i, j)
      var num8 = Math.pow(1.0 - i, (n - j))
      x += ((num6 * num7) * num8) * points[j][0]
      y += ((num6 * num7) * num8) * points[j][1]
    }
    list.push([x, y])
  }
  list.push(points[n])
  return list
}
// for bx 返回
plot.getBezierPoints2 = function (points) {
  // if (points.length = 2) {
  if (points.length === 2) {
    // return points
    // return { type: 'LineString', pntLs: points }
    return { type: 'LineString', data: points }
  }
  const list = [] // new Array()
  const n = points.length - 1
  for (var i = 0.0; i <= 1.0; i += 0.01) {
    var x = 0.0
    var y = 0.0
    for (var j = 0; j <= n; j++) {
      var num6 = plot.getBinomialFactor(n, j)
      var num7 = Math.pow(i, j)
      var num8 = Math.pow(1.0 - i, (n - j))
      x += ((num6 * num7) * num8) * points[j][0]
      y += ((num6 * num7) * num8) * points[j][1]
    }
    list.push([x, y])
  }
  list.push(points[n])
  // return list
  // return { type: 'LineString', pntLs: list } // 给mapbox使用的
  return { type: 'LineString', data: list } // 给ol使用
}

/* Method:getBSpline
 * 获取简单线箭头顶点
 * 参数points：绘制箭头的控制点, headHeightFactor, headWidthFactor箭头头部宽度因子
 * 返回：构成箭头的数组，需要构成多边形
*/
plot.getBSpline = function (points) {
  const pnts = plot.getBSplinePoints(points, 2)
  return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: pnts }] }
}

/* Method:getBSpline
 * 获取简单线箭头顶点
 * 参数points：绘制箭头的控制点, headHeightFactor, headWidthFactor箭头头部宽度因子
 * 返回：构成箭头的数组，需要构成多边形
*/
plot.getBezierArea = function (points) {
  const pnts = plot.getBSplinePoints(points, 2)
  return { geoType: 'GeometryCollection', geoData: [{ type: 'Polygon', data: [pnts] }] }
}

/** Method:getSLArrowPnts
 * 获取简单线箭头顶点
 * 参数points：绘制箭头的控制点, headHeightFactor, headWidthFactor箭头头部宽度因子
 * 返回：构成箭头的数组，需要构成多边形
 */
// plot.getSLArrowPnts = function (inpoints, headHeightFactor, headWidthFactor) {
//   let num = inpoints.length
//   if (num < 2) {
//     return null
//   }
//   let mulLine = []
//   if ((num >= 2) && (plot.geomEquals(inpoints[num - 1], inpoints[num - 2]))) {
//     let ctrlPoint = inpoints.slice(0, num - 1)
//     let list1 = plot.getArrowHeadPointsForSLine(ctrlPoint, headHeightFactor, headWidthFactor)
//     let list2 = plot.getBezierPoints(ctrlPoint)
//     mulLine = list2.concat(list1)
//   } else {
//     let list1 = plot.getArrowHeadPointsForSLine(inpoints, headHeightFactor, headWidthFactor)
//     let list2 = plot.getBezierPoints(inpoints)
//     // mulLine.push(list1)
//     // mulLine.push(list2)
//     mulLine = list2.concat(list1)
//   }
//   return mulLine
// }
// 为mapbox平台plus调整1; 为ol层调整2
plot.getSLArrowPnts = function (inpoints, headHeightFactor = plot.headHeightFactor, headWidthFactor = plot.headWidthFactor) {
  const num = inpoints.length
  if (num < 2) {
    return null
  }
  const mulLine = []
  if ((num >= 2) && (plot.geomEquals(inpoints[num - 1], inpoints[num - 2]))) {
    const ctrlPoint = inpoints.slice(0, num - 1)
    const list1 = plot.getArrowHeadPointsForSLine(ctrlPoint, headHeightFactor, headWidthFactor)
    const list2 = plot.getBezierPoints2(ctrlPoint)
    // mulLine = list2.concat(list1)
    if (list1) { // 如果箭头为空数据，不压入列表
      mulLine.push(list1)
    }
    mulLine.push(list2)
  } else {
    const list1 = plot.getArrowHeadPointsForSLine(inpoints, headHeightFactor, headWidthFactor)
    const list2 = plot.getBezierPoints2(inpoints)
    if (list1) {
      mulLine.push(list1)
    }
    mulLine.push(list2)
    // mulLine = list2.concat(list1)
  }
  // return mulLine
  return { geoType: 'GeometryCollection', geoData: mulLine }
}
// for mb 返回对象列表(添加了neckHeightFactor因子)
/** Method:getSSArrowPnts  （注意：由getSLArrowPnts2改名而来）
 * 获取简单线箭头顶点(实心多边形)
 * 参数points：绘制箭头的控制点, headHeightFactor, headWidthFactor箭头头部宽度因子，neckHeightFactor箭头颈长度因子
 * 返回：构成箭头的数组，需要构成多边形
 */
plot.getSSArrowPnts = function (inpoints, headHeightFactor = plot.headHeightFactor, headWidthFactor = plot.headWidthFactor, neckHeightFactor = plot.neckHeightFactor) {
  const num = inpoints.length
  if (num < 2) {
    return null
  }
  const mulLine = []
  if ((num >= 2) && (plot.geomEquals(inpoints[num - 1], inpoints[num - 2]))) {
    const ctrlPoint = inpoints.slice(0, num - 1)
    const list1 = plot.getArrowHeadPointsForSLine2(ctrlPoint, headHeightFactor, headWidthFactor, neckHeightFactor)
    const list2 = plot.getBezierPoints2(ctrlPoint)
    if (list1) {
      mulLine.push(list1)
    }
    mulLine.push(list2)
    // console.log(list1)
  } else {
    const list1 = plot.getArrowHeadPointsForSLine2(inpoints, headHeightFactor, headWidthFactor, neckHeightFactor)
    const list2 = plot.getBezierPoints2(inpoints)
    if (list1) {
      mulLine.push(list1)
    }
    mulLine.push(list2)
  }

  const res = { geoType: 'GeometryCollection', geoData: mulLine }
  // return mulLine
  return res
}
// 虚线箭头
plot.dashArrowPnts = function (inpoints, headHeightFactor = plot.headHeightFactor, headWidthFactor = plot.headWidthFactor, neckHeightFactor = plot.neckHeightFactor) {
  return plot.getSSArrowPnts(inpoints, headHeightFactor, headWidthFactor, neckHeightFactor)
}
// 路径箭头
// aStartPnt 开始的坐标点；aEndPnt 结束的坐标点； aPathPnts 路径坐标点aStartPnt, aEndPnt, aPathPnts
plot.pathArrowPnts = function (inpoints, headHeightFactor = plot.headHeightFactor, headWidthFactor = plot.headWidthFactor, neckHeightFactor = plot.neckHeightFactor) {
  const num = inpoints.length
  // console.log(num)
  if (num < 2) {
    return null
  }
  const mulLine = []
  if ((num >= 2) && (plot.geomEquals(inpoints[num - 1], inpoints[num - 2]))) {
    const ctrlPoint = inpoints.slice(0, num - 1)
    const list1 = plot.getArrowHeadPointsForSLine3(ctrlPoint, headHeightFactor, headWidthFactor, neckHeightFactor)
    const list2 = { type: 'LineString', data: inpoints }
    if (list1) {
      mulLine.push(list1)
    }
    mulLine.push(list2)
    // console.log(list1)
  } else {
    const list1 = plot.getArrowHeadPointsForSLine3(inpoints, headHeightFactor, headWidthFactor, neckHeightFactor)
    const list2 = { type: 'LineString', data: inpoints }
    if (list1) {
      mulLine.push(list1)
    }
    mulLine.push(list2)
  }

  const res = { geoType: 'GeometryCollection', geoData: mulLine }
  // return mulLine
  return res
  // return plot.getSSArrowPnts(aPathPnts, headHeightFactor, headWidthFactor, neckHeightFactor)
}
// 虚线路径箭头
plot.dashPathArrowPnts = function (inpoints, headHeightFactor = plot.headHeightFactor, headWidthFactor = plot.headWidthFactor, neckHeightFactor = plot.neckHeightFactor) {
  return plot.pathArrowPnts(inpoints, headHeightFactor, headWidthFactor, neckHeightFactor)
}

plot.getArrowBodyPoints = function (points, neckLeftPoint, neckRightPoint, tailWidthFactor, leftFactor, rightFactor) {
  if (points.length < 2) {
    return points
  }
  const num = plot.wholeDistance(points)
  const num3 = plot.wholeDistance(points) * tailWidthFactor
  const num4 = plot.CalLengthOfTwoPoints(neckLeftPoint, neckRightPoint)
  const num5 = num3 - (num4 / 2.0)
  let num6 = 0.0
  const list = [] // new Array()
  const list2 = [] // new Array()
  for (var i = 1; i < (points.length - 1); i++) {
    const angle = plot.getAngleOfThreePoints(points[i - 1], points[i], points[i + 1]) / 2.0
    num6 += plot.CalLengthOfTwoPoints(points[i - 1], points[i])
    const num9 = (num3 - ((num6 / num) * num5)) / Math.sin(angle)
    list.push(plot.getThirdPoint(points[i - 1], points[i], angle, num9 * leftFactor, 'right'))
    list2.push(plot.getThirdPoint(points[i - 1], points[i], Math.PI - angle, num9 * rightFactor, 'left'))
  }
  for (var j = 0; j < list2.length; j++) {
    list.push(list2[j])
  }
  return list
}

plot.getArrowTailPoints = function (points, tailWidthFactor, hasSwallowTail, swallowTailFactor) {
  if (points.length < 2) {
    return points
  }
  const length = plot.wholeDistance(points) * tailWidthFactor
  const list = [] // new Array();
  const point = plot.getThirdPoint(points[1], points[0], 1.5 * Math.PI, length, 'right')
  const point2 = plot.getThirdPoint(points[1], points[0], 1.5 * Math.PI, length, 'left')
  if (hasSwallowTail) {
    var num3 = length * swallowTailFactor
    var point3 = plot.getThirdPoint(points[1], points[0], 0.0, num3, 'left')
    list.push(point)
    list.push(point3)
    list.push(point2)
    return list
  }
  list.push(point)
  list.push(point2)
  return list
}
// 简单箭头
plot.getSimpleArrowPnts = function (inpoints, hasSwallowTail, swallowTailFactor, curveFitMethod, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor, tailWidthFactor) {
  if (inpoints.length < 2) {
    // return inpoints 小于一个控制点，不做处理。返回null
    return null
  }
  // 获取箭头顶点
  const list2 = plot.getArrowHeadPoints(inpoints, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)
  const neckLeftPoint = list2[0]
  const neckRightPoint = list2[4]
  const list3 = plot.getArrowBodyPoints(inpoints, neckLeftPoint, neckRightPoint, tailWidthFactor, 1.0, 1.0)
  const list4 = plot.getArrowTailPoints(inpoints, tailWidthFactor, hasSwallowTail, swallowTailFactor)
  const point3 = list4[0]

  const point4 = (list4.length === 3) ? list4[1] : list4[1]
  const point5 = (list4.length === 3) ? list4[2] : list4[1]
  const num = list3.length
  const range = list3.slice(0, Math.ceil(num / 2))
  const list6 = list3.slice(Math.ceil(num / 2))
  range.push(neckLeftPoint)
  list6.push(neckRightPoint)
  range.reverse()
  range.push(point3)
  list6.reverse()
  list6.push(point5)

  let rangNew = null
  let list6New = null

  // console.log(curveFitMethod)  // 0603注释
  if (curveFitMethod === 'useBezierFit') {
    rangNew = plot.getBezierPoints(range)
    list6New = plot.getBezierPoints(list6)
  } else {
    rangNew = plot.getBSplinePoints(range, 2)
    list6New = plot.getBSplinePoints(list6, 2)
  }
  if (point4 != null) {
    rangNew.push(point4)
    list6New.push(point4)
  }
  rangNew.reverse()
  for (var i = 0; i < list2.length; i++) {
    rangNew.push(list2[i])
  }
  for (var j = 0; j < list6New.length; j++) {
    rangNew.push(list6New[j])
  }
  // return rangNew
  // return [{ type: 'Polygon', pntLs: rangNew }]  // 返回mapbox格式数据
  return { geoType: 'GeometryCollection', geoData: [{ type: 'Polygon', data: [rangNew] }] } // 返回ol格式数据
}
// 简单箭头-带燕尾function (inpoints, hasSwallowTail = true, swallowTailFactor = 0.5, curveFitMethod = 'useBezierFit', headHeightFactor = 0.2, headWidthFactor = 0.5, neckHeightFactor = 0.8, neckWidthFactor = 0.2, tailWidthFactor = 0.1)
plot.getSimpleArrowST = function (inpoints, hasSwallowTail = true, swallowTailFactor = 0.5, curveFitMethod = 'useBezierFit', headHeightFactor = 0.15, headWidthFactor = 0.3, neckHeightFactor = 0.75, neckWidthFactor = 0.12, tailWidthFactor = 0.07) {
  return plot.getSimpleArrowPnts(inpoints, hasSwallowTail, swallowTailFactor, curveFitMethod, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor, tailWidthFactor)
}
// 简单箭头-无燕尾
plot.getSimpleArrow = function (inpoints, hasSwallowTail = false, swallowTailFactor = 0.5, curveFitMethod = 'useBezierFit', headHeightFactor = 0.15, headWidthFactor = 0.3, neckHeightFactor = 0.75, neckWidthFactor = 0.12, tailWidthFactor = 0.07) {
  return plot.getSimpleArrowPnts(inpoints, hasSwallowTail, swallowTailFactor, curveFitMethod, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor, tailWidthFactor)
}
// 简单箭头-无燕尾等宽
plot.getSimpleArrowEW = function (inpoints, hasSwallowTail = false, swallowTailFactor = 0.5, curveFitMethod = 'useBezierFit', headHeightFactor = 0.15, headWidthFactor = 0.3, neckHeightFactor = 0.75, neckWidthFactor = 0.12, tailWidthFactor = 0.025) {
  return plot.getSimpleArrowPnts(inpoints, hasSwallowTail, swallowTailFactor, curveFitMethod, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor, tailWidthFactor)
}

// 简单箭头--有展开宽度(基础函数)
plot.getAttackArrowPnts = function (inpoints, hasSwallowTail, swallowTailFactor, curveFitMethod, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor, tailWidthFactor) {
  if (inpoints.length < 2) {
    // return inpoints
    return null
  }
  if (inpoints.length === 2) {
    // return [{ type: 'LineString', pntLs: inpoints }] // 此为mapbox格式
    return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: inpoints }] }
  }
  const inpointsM = [] // 保存新的定点信息！
  let iTailWidthFactor = tailWidthFactor
  if (inpoints.length > 2) {
    const pnt3 = plot.getMidPoint(inpoints[0], inpoints[1])
    inpointsM.push(pnt3)
    for (let i = 2; i < inpoints.length; i++) {
      inpointsM.push(inpoints[i])
    }
    const tailWidth = plot.CalLengthOfTwoPoints(inpoints[0], inpoints[1]) / 2 // 获得燕尾的宽度
    const arrowLen = plot.wholeDistance(inpointsM)
    iTailWidthFactor = tailWidth / arrowLen
  }
  // 获取箭头顶点
  const list2 = plot.getArrowHeadPoints(inpointsM, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)
  const neckLeftPoint = list2[0]
  const neckRightPoint = list2[4]
  const list3 = plot.getArrowBodyPoints(inpointsM, neckLeftPoint, neckRightPoint, iTailWidthFactor, 1.0, 1.0)
  const list4 = plot.getArrowTailPoints(inpointsM, iTailWidthFactor, hasSwallowTail, swallowTailFactor)
  const point3 = list4[0]

  // let point4 = (list4.length === 3) ? list4[1] : list4[1]
  const point5 = (list4.length === 3) ? list4[2] : list4[1]
  const num = list3.length
  const range = list3.slice(0, Math.ceil(num / 2))
  const list6 = list3.slice(Math.ceil(num / 2))
  range.push(neckLeftPoint)
  list6.push(neckRightPoint)
  range.reverse()
  range.push(point3)
  list6.reverse()
  list6.push(point5)

  let rangNew = null
  let list6New = null

  // console.log(curveFitMethod)  // 0603注释
  if (curveFitMethod === 'useBezierFit') {
    rangNew = plot.getBezierPoints(range)
    list6New = plot.getBezierPoints(list6)
  } else {
    rangNew = plot.getBSplinePoints(range, 2)
    list6New = plot.getBSplinePoints(list6, 2)
  }
  // 去除尾部连线;注释额上面的point4
  // if (point4 != null) {
  //   rangNew.push(point4)
  //   list6New.push(point4)
  // }
  rangNew.reverse()
  for (var i = 0; i < list2.length; i++) {
    rangNew.push(list2[i])
  }
  for (var j = 0; j < list6New.length; j++) {
    rangNew.push(list6New[j])
  }
  // return rangNew
  // return [{ type: 'Polygon', pntLs: rangNew }]
  // return [{ type: 'LineString', pntLs: rangNew }] // 此为mapbox格式
  return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: rangNew }] } // 返回ol格式数据
}

// 简单箭头--有展开宽度
plot.getAttackArrow = function (inpoints, hasSwallowTail = false, swallowTailFactor = 0.5, curveFitMethod = 'useBezierFit', headHeightFactor = 0.15, headWidthFactor = 0.3, neckHeightFactor = 0.75, neckWidthFactor = 0.12, tailWidthFactor = 0.07) {
  return plot.getAttackArrowPnts(inpoints, hasSwallowTail, swallowTailFactor, curveFitMethod, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor, tailWidthFactor)
}

// 绘制圆弧--获取中心
plot.getArcPnts = function (inpoints) {
  if (inpoints.length < 2) {
    return inpoints
  }
  if (inpoints.length === 2) {
    // return [{ type: 'LineString', pntLs: inpoints }]  // 此为mapbox
    return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: inpoints }] }
  }
  // 上点确定一个圆弧
  if (inpoints.length > 2) {
    const cc = plot.getCircleCenterOfThreePoints(inpoints[0], inpoints[1], inpoints[2])
    // let r = plot.CalLengthOfTwoPoints(cc, inpoints[0])
    return cc
  }
}

// 获取弧形顶点--暂不使用
// plot.getArcPoints = function (center, radius, startAngle, endAngle) {
//   let x = null
//   let y = null
//   let pnts = []
//   let angleDiff = endAngle - startAngle

//   angleDiff = angleDiff < 0 ? angleDiff + Math.PI * 2 : angleDiff
//   for (var i = 0; i <= 100; i++) {
//     var angle = startAngle + angleDiff * i / 100
//     x = center[0] + radius * Math.cos(angle)
//     y = center[1] + radius * Math.sin(angle)
//     pnts.push([x, y])
//   }
//   // return pnts
//   // return [{ type: 'LineString', pntLs: pnts }]  // 此为mapbox格式
//   return {geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: pnts }]}
// }

//  获取弧形顶点（为ol新添加）
plot.getArcPoints = function (inpoints) {
  if (inpoints.length === 2) {
    // return {geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: inpoints }]}
    return plot.getArcPnts(inpoints) // 返回两点确定的线段
  } else if (inpoints.length > 2) {
    const cc = plot.getArcPnts(inpoints)
    const radius = plot.CalLengthOfTwoPoints(cc, inpoints[0])
    // 计算角度
    const b1 = Math.atan2(inpoints[0][1] - cc[1], inpoints[0][0] - cc[0])
    const b2 = Math.atan2(inpoints[1][1] - cc[1], inpoints[1][0] - cc[0])
    // 计算顺时还是逆时针
    let startAngle = null
    let endAngle = null
    if (plot.isClockWise(inpoints[0], inpoints[1], inpoints[2])) {
      startAngle = b2
      endAngle = b1
    } else {
      startAngle = b1
      endAngle = b2
    }
    // 绘制弧线
    let theta = (endAngle - startAngle) / 50
    if (theta < 0) {
      endAngle += 2 * Math.PI
      theta = (endAngle - startAngle) / 50
    }
    const xArray = []
    let x
    let y
    for (let i = startAngle; i < endAngle; i += theta) {
      x = radius * Math.cos(i) + cc[0]
      y = radius * Math.sin(i) + cc[1]
      xArray.push([x, y])
    }
    // plotCoord = [{ type: 'LineString', pntLs: xArray }]
    return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: xArray }] }
  }
}

plot.geomEquals = function (geom, geom1) {
  var equals = false
  if (geom != null) {
    equals = ((geom1[0] === geom[0] && geom1[1] === geom[1]))
  }
  return equals
}

plot.getMidPoint = function (pnt1, pnt2) {
  const pnt3 = [] // new Array();
  const x = (pnt1[0] + pnt2[0]) / 2.0
  const y = (pnt1[1] + pnt2[1]) / 2.0
  pnt3.push(x)
  pnt3.push(y)
  return pnt3
}

plot.getTempPnt4 = function (linePnt1, linePnt2, point) {
  let point4 = null
  const point3 = plot.getMidPoint(linePnt1, linePnt2)
  const num = plot.CalLengthOfTwoPoints(point3, point)
  const num2 = plot.getAngleOfThreePoints(linePnt1, point3, point)

  let length = 0.0
  let num4 = 0.0

  if (num2 < Math.PI / 2) {
    length = num * Math.sin(num2)
    num4 = num * Math.cos(num2)
    point4 = plot.getThirdPoint(linePnt1, point3, 1.5 * Math.PI, length, 'left')
    return plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'right')
    // point5 = plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'right')
  } else if ((num2 >= Math.PI / 2) && (num2 < Math.PI)) {
    length = num * Math.sin(Math.PI - num2)
    num4 = num * Math.cos(Math.PI - num2)
    point4 = plot.getThirdPoint(linePnt1, point3, 1.5 * Math.PI, length, 'left')
    return plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'left')
    // point5 = plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'left')
  } else if ((num2 >= Math.PI) && (num2 < 1.5 * Math.PI)) {
    length = num * Math.sin(num2 - Math.PI)
    num4 = num * Math.cos(num2 - Math.PI)
    point4 = plot.getThirdPoint(linePnt1, point3, 1.5 * Math.PI, length, 'right')
    return plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'right')
    // point5 = plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'right')
  } else {
    length = num * Math.sin(2 * Math.PI - num2)
    num4 = num * Math.cos(2 * Math.PI - num2)
    point4 = plot.getThirdPoint(linePnt1, point3, 1.5 * Math.PI, length, 'right')
    return plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'left')
    // point5 = plot.getThirdPoint(point3, point4, 1.5 * Math.PI, num4, 'left')
  }
}

plot.getArrowPoints = function (pnt1, pnt2, pnt3, side, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor) {
  var point = plot.getMidPoint(pnt1, pnt2)
  const num = plot.CalLengthOfTwoPoints(point, pnt3)
  let endPnt = plot.getThirdPoint(pnt3, point, 0.0, num * 0.3, 'left')
  let point3 = plot.getThirdPoint(pnt3, point, 0.0, num * 0.5, 'left')
  let point4 = plot.getThirdPoint(pnt3, point, 0.0, num * 0.7, 'left')

  endPnt = plot.getThirdPoint(point, endPnt, 1.5 * Math.PI, num / 4.0, side)
  point3 = plot.getThirdPoint(point, point3, 1.5 * Math.PI, num / 4.0, side)
  point4 = plot.getThirdPoint(point, point4, 1.5 * Math.PI, num / 4.0, side)

  const points = [] // new Array()
  points.push(point)
  points.push(endPnt)
  points.push(point3)
  points.push(point4)
  points.push(pnt3)

  const list2 = plot.getArrowHeadPoints(points, headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)
  const neckLeftPoint = list2[0]
  const neckRightPoint = list2[4]

  const tailWidthFactor = (plot.CalLengthOfTwoPoints(pnt1, pnt2) / plot.wholeDistance(points)) / 2.0
  const leftFactor = (side === 'left') ? 1.0 : 0.01
  const rightFactor = (side === 'left') ? 0.01 : 1.0
  const list3 = plot.getArrowBodyPoints(points, neckLeftPoint, neckRightPoint, tailWidthFactor, leftFactor, rightFactor)
  const num5 = list3.length

  const range = list3.slice(0, Math.ceil(num5 / 2))
  const list5 = list3.slice(Math.ceil(num5 / 2))

  range.push(neckLeftPoint) // 3+1
  list5.push(neckRightPoint) // 3+1
  range.reverse()
  range.push(pnt1) // 4+1
  list5.reverse()
  list5.push(pnt2)
  range.reverse() // 4+1

  for (let i = 0; i < list2.length; i++) {
    range.push(list2[i])
  }
  for (let i = 0; i < list5.length; i++) {
    range.push(list5[i])
  }

  return range
}

// mb 双箭头绘制 返回对象{ type: 'Polygon', pntLs: range }
// ol 返回
plot.getDoubleArrowPnts = function (inpoints, headHeightFactor = 0.2, headWidthFactor = 0.5, neckHeightFactor = 0.8, neckWidthFactor = 0.2) {
  let range = null

  const num = inpoints.length
  // 有两个点时，画直线
  if (num === 2) {
    // return [{ type: 'LineString', pntLs: inpoints }]
    return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: inpoints }] }
  }
  if (num > 4) {
    // console.log(num)  // 0603注释
  }

  if ((num >= 3) && (!plot.geomEquals(inpoints[num - 1], inpoints[num - 2]))) {
    const point = inpoints[0]
    const point2 = inpoints[1]
    const point3 = inpoints[2]
    let point4 = null
    if (num === 3) {
      point4 = plot.getTempPnt4(point, point2, point3)
    } else {
      point4 = inpoints[3]
    }
    const connPointTemp = plot.getMidPoint(point, point2)

    const list = plot.getArrowPoints(point, connPointTemp, point4, 'left', headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)
    const list2 = plot.getArrowPoints(connPointTemp, point2, point3, 'right', headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)

    const num2 = list.length
    // console.log('num:' + num2)
    const num3 = Math.ceil((num2 - 5) / 2)
    range = list.slice(0, num3)
    const list4 = list.slice(num3, num3 + 5)
    const list5 = list.slice(num3 + 5)
    const list6 = list2.slice(0, num3)
    const list7 = list2.slice(num3, num3 + 5)
    let list8 = list2.slice(num3 + 5)
    range = plot.getBezierPoints(range)
    for (let i = 0; i < list6.length; i++) {
      list5.push(list6[i])
    }
    const list9 = plot.getBezierPoints(list5)
    list8 = plot.getBezierPoints(list8)

    for (let i = 0; i < list4.length; i++) {
      range.push(list4[i])
    }
    for (let i = 0; i < list9.length; i++) {
      range.push(list9[i])
    }
    for (let i = 0; i < list7.length; i++) {
      range.push(list7[i])
    }
    for (let i = 0; i < list8.length; i++) {
      range.push(list8[i])
    }
    if (range.length > 0) {
      if (!plot.geomEquals(range[0], range[range.length - 1])) {
        range.push(range[0])
      }
    }
  } else {
    range = inpoints
  }
  // return range
  // mb格式
  // return [{ type: 'Polygon', pntLs: range }]
  // console.log(range)
  return { geoType: 'GeometryCollection', geoData: [{ type: 'Polygon', data: [range] }] }
}
// 双箭头绘制 返回对象{ type: 'LineString', pntLs: range }
plot.getDoubleArrowLine = function (inpoints, headHeightFactor = 0.2, headWidthFactor = 0.5, neckHeightFactor = 0.8, neckWidthFactor = 0.2) {
  let range = null

  const num = inpoints.length
  // 有两个点时，画直线
  if (num === 2) {
    // return [{ type: 'LineString', pntLs: inpoints }]
    return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: inpoints }] }
  }
  if (num > 4) {
    // console.log(num)  // 0603注释
  }

  if ((num >= 3) && (!plot.geomEquals(inpoints[num - 1], inpoints[num - 2]))) {
    const point = inpoints[0]
    const point2 = inpoints[1]
    const point3 = inpoints[2]
    let point4 = null
    if (num === 3) {
      point4 = plot.getTempPnt4(point, point2, point3)
    } else {
      point4 = inpoints[3]
    }
    const connPointTemp = plot.getMidPoint(point, point2)

    const list = plot.getArrowPoints(point, connPointTemp, point4, 'left', headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)
    const list2 = plot.getArrowPoints(connPointTemp, point2, point3, 'right', headHeightFactor, headWidthFactor, neckHeightFactor, neckWidthFactor)

    const num2 = list.length
    // console.log('num:' + num2)
    const num3 = Math.ceil((num2 - 5) / 2)
    range = list.slice(0, num3)
    const list4 = list.slice(num3, num3 + 5)
    const list5 = list.slice(num3 + 5)
    const list6 = list2.slice(0, num3)
    const list7 = list2.slice(num3, num3 + 5)
    let list8 = list2.slice(num3 + 5)
    range = plot.getBezierPoints(range)
    for (let i = 0; i < list6.length; i++) {
      list5.push(list6[i])
    }
    const list9 = plot.getBezierPoints(list5)
    list8 = plot.getBezierPoints(list8)

    for (let i = 0; i < list4.length; i++) {
      range.push(list4[i])
    }
    for (let i = 0; i < list9.length; i++) {
      range.push(list9[i])
    }
    for (let i = 0; i < list7.length; i++) {
      range.push(list7[i])
    }
    for (let i = 0; i < list8.length; i++) {
      range.push(list8[i])
    }
    // if (range.length > 0) {
    //   if (!plot.geomEquals(range[0], range[range.length - 1])) {
    //     range.push(range[0])
    //   }
    // }
  } else {
    range = inpoints
  }
  // return range
  // mb格式
  // return [{ type: 'Polygon', pntLs: range }]
  // console.log(range)
  return { geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: range }] }
}

// 三点确定圆心
plot.getCircleCenterOfThreePoints = function (point1, point2, point3) {
  var pntA = [(point1[0] + point2[0]) / 2, (point1[1] + point2[1]) / 2]
  var pntB = [pntA[0] - point1[1] + point2[1], pntA[1] + point1[0] - point2[0]]
  var pntC = [(point1[0] + point3[0]) / 2, (point1[1] + point3[1]) / 2]
  var pntD = [pntC[0] - point1[1] + point3[1], pntC[1] + point1[0] - point3[0]]
  return plot.getIntersectPoint(pntA, pntB, pntC, pntD)
}

plot.getIntersectPoint = function (pntA, pntB, pntC, pntD) {
  if (pntA[1] === pntB[1]) {
    var _f = (pntD[0] - pntC[0]) / (pntD[1] - pntC[1])
    var _x = _f * (pntA[1] - pntC[1]) + pntC[0]
    var _y = pntA[1]
    return [_x, _y]
  }
  if (pntC[1] === pntD[1]) {
    var _e = (pntB[0] - pntA[0]) / (pntB[1] - pntA[1])
    var _x2 = _e * (pntC[1] - pntA[1]) + pntA[0]
    var _y2 = pntC[1]
    return [_x2, _y2]
  }
  var e = (pntB[0] - pntA[0]) / (pntB[1] - pntA[1])
  var f = (pntD[0] - pntC[0]) / (pntD[1] - pntC[1])
  var y = (e * pntA[1] - pntA[0] - f * pntC[1] + pntC[0]) / (e - f)
  var x = e * y - e * pntA[1] + pntA[0]
  return [x, y]
}

plot.CreateNewVertices = function (arg) {
  if (arg != null && arg.length >= 2) {
    var maxX = Math.max(arg[0][0], arg[1][0])
    var minX = Math.min(arg[0][0], arg[1][0])
    var maxY = Math.max(arg[0][1], arg[1][1])
    var minY = Math.min(arg[0][1], arg[1][1])
    var pnt1 = [minX, maxY]
    var pnt2 = [maxX, minY]
    arg.splice(0, 1, pnt1)
    arg.splice(1, 1, pnt2)
  }
}

plot.GetTriangleFlagDots = function (arg) {
  plot.CreateNewVertices(arg)
  const locPnts = []

  const num = arg.length
  if ((num >= 2) && (!plot.geomEquals(arg[num - 1], arg[num - 2]))) {
    const point = arg[0]
    const point2 = arg[1]
    const point3 = [point[0], point2[1]]
    const point4 = plot.getMidPoint(point, point3)
    const point5 = [point2[0], point4[1]]

    locPnts.push(point3)
    locPnts.push(point4)
    locPnts.push(point)
    locPnts.push(point5)
    locPnts.push(point4)
  }
  return locPnts
}

plot.GetRectFlagDots = function (arg) {
  plot.CreateNewVertices(arg)
  const locPnts = []
  const num = arg.length
  if ((num >= 2) && (!plot.geomEquals(arg[num - 1], arg[num - 2]))) {
    const point = arg[0]
    const point2 = arg[1]
    const point3 = [point[0], point2[1]]
    const point4 = plot.getMidPoint(point, point3)
    const point5 = [point2[0], point4[1]]
    const point6 = [point2[0], point[1]]

    locPnts.push(point3)
    locPnts.push(point4)
    locPnts.push(point)
    locPnts.push(point6)
    locPnts.push(point5)
    locPnts.push(point4)
  }
  return locPnts
}

plot.GetCurveFlagDots = function (arg) {
  plot.CreateNewVertices(arg)
  const locPnts = []
  const num = arg.length
  if ((num >= 2) && (!plot.geomEquals(arg[num - 1], arg[num - 2]))) {
    const point = arg[0]
    const point2 = arg[1]
    const point3 = [point[0], point2[1]]
    const point4 = plot.getMidPoint(point, point3)
    const point5 = [point2[0], point4[1]]
    const point6 = [point2[0], point[1]]

    const length = plot.CalLengthOfTwoPoints(point, point4) / 2.0
    const num3 = plot.CalLengthOfTwoPoints(point, point6)
    let endPnt = plot.getThirdPoint(point6, point, 0.0, num3 / 4.0, 'left')
    const point8 = plot.getThirdPoint(point, endPnt, Math.PI * 1.5, length, 'right')
    endPnt = plot.getThirdPoint(point6, point, 0.0, (num3 / 4.0) * 3.0, 'left')
    const point9 = plot.getThirdPoint(point, endPnt, Math.PI * 1.5, length, 'left')
    endPnt = plot.getThirdPoint(point5, point4, 0.0, num3 / 4.0, 'left')
    const point10 = plot.getThirdPoint(point4, endPnt, Math.PI * 1.5, length, 'right')
    endPnt = plot.getThirdPoint(point5, point4, 0.0, (num3 / 4.0) * 3.0, 'left')
    const point11 = plot.getThirdPoint(point4, endPnt, Math.PI * 1.5, length, 'left')

    const list = []
    list.push(point)
    list.push(point8)
    list.push(point9)
    list.push(point6)
    const list2 = plot.getBezierPoints(list)
    const list3 = []
    list3.push(point4)
    list3.push(point10)
    list3.push(point11)
    list3.push(point5)
    const list4 = plot.getBezierPoints(list3)

    const polyPnts = []
    polyPnts.push(point4)
    for (let i = 0; i < list2.length; i++) {
      polyPnts.push(list2[i])
    }

    locPnts.push(point3)
    locPnts.push(point4)
    locPnts.push(point)
    for (let i = 0; i < list2.length; i++) {
      locPnts.push(list2[i])
    }
    locPnts.push(point5)
    const listx = list4.reverse()
    for (let i = 0; i < list4.length; i++) {
      locPnts.push(listx[i])
    }
  }
  return locPnts
}

plot.GetAssemblyAreaDots = function (arg1) {
  let loc2 = null
  let loc3 = null
  let loc4 = 0
  let loc5 = null
  let loc6 = null
  let loc7 = null
  let loc8 = null
  let loc9 = null
  let loc10 = null
  let loc11 = null
  let loc12 = null
  let loc13 = null
  let loc14 = null
  const loc1 = arg1.length
  if (loc1 >= 2 && !(arg1[loc1 - 1] === arg1[loc1 - 2])) {
    loc2 = arg1[0]
    loc3 = arg1[1]
    loc4 = plot.CalLengthOfTwoPoints(loc2, loc3)
    loc5 = plot.getMidPoint(loc2, loc3)
    loc6 = plot.getThirdPoint(loc2, loc5, Math.PI * 1.5, loc4 / 4.5, 'right')
    loc7 = plot.getThirdPoint(loc2, loc3, 0, loc4 * 0.8, 'left')
    loc8 = plot.getThirdPoint(loc2, loc7, Math.PI * 1.5, loc4 / 5, 'left')
    loc9 = plot.getThirdPoint(loc2, loc3, 0, loc4 * 0.45, 'left')
    loc10 = plot.getThirdPoint(loc2, loc9, Math.PI * 1.5, loc4 / 10, 'left')
    loc11 = plot.getThirdPoint(loc2, loc3, 0, loc4 * 0.15, 'left')
    loc12 = plot.getThirdPoint(loc2, loc11, Math.PI * 1.5, loc4 / 7, 'left')
    loc13 = []
    loc14 = []
    loc14.push(loc2, loc6, loc3, loc12, loc10, loc8)
    loc13 = plot.getAdvancedBezierPoints(loc14)
  }
  // return loc13
  return [{ type: 'Polygon', pntLs: loc13 }]
}

plot.getAdvancedBezierPoints = function (arg1) {
  var loc8 = 0
  var loc9 = 0
  var loc10 = 0
  var loc11 = 0
  var loc12 = 0
  var loc13 = 0
  arg1 = arg1.slice()
  var loc1 = arg1.length
  arg1.push(arg1[0])
  var loc2 = []
  var loc3 = 0
  while (loc3 < loc1) {
    loc2.push(plot.getMidPoint(arg1[loc3], arg1[loc3 + 1]))
    ++loc3
  }
  loc2.push(loc2[0])
  arg1.push(arg1[1])
  var loc4 = []
  loc3 = 0
  while (loc3 < loc1) {
    loc8 = plot.CalLengthOfTwoPoints(arg1[loc3], arg1[loc3 + 1])
    loc9 = plot.CalLengthOfTwoPoints(arg1[loc3 + 1], arg1[loc3 + 2])
    loc10 = plot.CalLengthOfTwoPoints(loc2[loc3], loc2[loc3 + 1])
    loc11 = loc10 * loc8 / (loc8 + loc9)
    loc4.push(plot.getThirdPoint(loc2[loc3 + 1], loc2[loc3], 0, loc11, 'left'))
    ++loc3
  }
  var loc5 = []
  loc3 = 0
  while (loc3 < loc1) {
    loc12 = arg1[loc3 + 1][0] - loc4[loc3][0]
    loc13 = arg1[loc3 + 1][1] - loc4[loc3][1]

    loc5.push([loc2[loc3][0] + loc12, loc2[loc3][1] + loc13])
    loc5.push(arg1[loc3 + 1])
    loc5.push([loc2[loc3 + 1][0] + loc12, loc2[loc3 + 1][1] + loc13])
    ++loc3
  }
  var loc6 = []
  var loc7 = loc5.slice()
  loc7.push(loc5[0], loc5[1])
  loc3 = 1
  while (loc3 < loc7.length) {
    loc6 = loc6.concat(plot.getBezierPoints(loc7.slice(loc3, loc3 + 4)))
    loc3 = loc3 + 3
  }
  return loc6
}

plot.GetCompassDots = function (arg1) {
  if (arg1 == null || arg1.length < 2) {
    return null
  }
  const loc4 = []
  const width = Math.abs(arg1[1][0] - arg1[0][0])
  const height = Math.abs(arg1[1][1] - arg1[0][1])
  const loc1 = [arg1[0][0] + width / 2, arg1[0][1]]
  loc4.push(loc1)
  const loc2 = [arg1[0][0] + width, arg1[0][1] - height]
  loc4.push(loc2)
  const loc3 = [arg1[0][0] + width / 2, arg1[0][1] - height / 4 * 3]
  loc4.push(loc3)

  const loc8 = []
  const loc5 = [arg1[0][0] + width / 2, arg1[0][1]]
  loc8.push(loc5)
  const loc6 = [arg1[0][0], arg1[0][1] - height]
  loc8.push(loc6)
  const loc7 = [arg1[0][0] + width / 2, arg1[0][1] - height / 4 * 3]
  loc8.push(loc7)

  const loc9 = []

  loc9.push(loc1)
  loc9.push(loc2)
  loc9.push(loc3)
  loc9.push(loc5)
  loc9.push(loc6)
  loc9.push(loc7)

  return loc9
}

// 机动行进方式
plot.getCyyLine_old = function (points, dl = 10000) {
  let bLine01 = null
  let bLine02 = null
  const cyy = []
  // 动态获取间距值
  const distance = plot.CalLengthOfTwoPoints(points[0], points[1]) * plot.headHeightFactor // 获取箭头长度（前两点）
  dl = -distance * plot.headWidthFactor // 获取箭头宽度
  // if(points.length==1){
  //   return // 一个点不做处理
  // }else if(points.length==2){
  // if(points.length==2){
  //   // return { type: 'LineString', data: points }
  //   return {geoType: 'GeometryCollection', geoData: [{ type: 'LineString', data: points }]}
  // }else{
  if (points.length > 1) {
    // 箭头部分
    const iArrow = plot.getArrowHeadPointsForSLine2(points, plot.headHeightFactor, plot.headWidthFactor, plot.neckHeightFactor)
    // 计算贝赛尔曲线；points为传入的贝塞尔控制点。
    if (points.length === 2) {
      bLine01 = points // { type: 'LineString', data: list }
    } else {
      bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    }
    bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    const P = JSON.parse(JSON.stringify(bLine01.data))
    cyy.push(iArrow)
    cyy.push(bLine01)
    // 创建平行线数组
    const Pnew = [] // new Array(Math.floor(P.length+1))
    const dlt = new Array(Math.floor(P.length + 1)) // 两条线间距-绘制圆时的直径
    // var P1={x:2*(points[1].x-points[0].x),y:2*(points[1].y-points[0].y)}
    const P1 = { x: 2 * (points[1][0] - points[0][0]), y: 2 * (points[1][1] - points[0][1]) }
    // 两条线的距离
    // Pnew[0]={x:points[0].x-P1.y*dl/Math.sqrt(Math.pow(P1.x,2)+Math.pow(P1.y,2)),
    //     y:points[0].y+P1.x*dl/Math.sqrt(Math.pow(P1.x,2)+Math.pow(P1.y,2))}
    // Pnew[0]={x:points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x,2) + Math.pow(P1.y,2)),
    // y:points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x,2) + Math.pow(P1.y,2))}
    Pnew[0] = [points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2)),
      points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2))]
    // console.log('-----:',Pnew[0])
    // console.log(points[0][0],P1.y * dl,Math.pow(P1.x,2),Math.pow(P1.y,2))
    // P[0]=points[0]
    // P[1]=line.pointAt(1)
    let x12 // 点1和点2的x距离
    let y12 // 点1和点2的y距离
    let x01 // 点1和点0的x距离
    let y01 // 点1和点0的y距离
    let a
    let b
    let k
    let r
    // var line1
    for (let i = 1; i < P.length - 1; i++) {
      // if(i==Math.floor(line.length()-1)){P[i+1]=line.pointAt(line.length())}else{
      // P[i+1]=line.pointAt(i+1)
      x12 = P[i + 1][0] - P[i][0]
      y12 = P[i + 1][1] - P[i][1]
      x01 = P[i][0] - P[i - 1][0]
      y01 = P[i][1] - P[i - 1][1]
      if (x12 === 0) {
        a = Math.PI / 2
        if (y12 < 0) { a = -a }
      } else {
        a = Math.atan2(y12, x12)
      }
      if (x01 === 0) {
        b = Math.PI / 2
        if (y01 < 0) { b = -b }
      } else {
        b = Math.atan2(y01, x01)
      }
      k = (b - a - Math.PI) / 2
      r = a + k
      dlt[i] = dl / Math.sin(k)
      // Pnew[i]={x:P[i][0]+dlt[i]*Math.cos(r),y:P[i][1]+dlt[i]*Math.sin(r)}
      // Pnew[i]=[P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      const newPnt = [P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      if (newPnt) {
        Pnew.push(newPnt)
      }
      // 改成画直线line1=group.line(Pnew[i-1].x,Pnew[i-1].y,Pnew[i].x,Pnew[i].y).stroke({color:'black', width:2})
      // console.log(x12,y12,x01,y01,a,b,k,r)
      // console.log(P[i][0],dlt[i],Math.cos(r),P[i][1],Math.sin(r))
      // console.log(Pnew)
    }
    // Pnew.splice(100,2)
    bLine02 = { type: 'LineString', data: Pnew }

    cyy.push(bLine02)
    // for(let x=0; x<Pnew.length; x++){
    //   console.log('out:',x,Pnew[x])
    // }
    console.log(bLine01, bLine02)
    // let res = {geoType: 'GeometryCollection', geoData: cyy}
    // return res
    // 绘制跟随箭头到此结束
    if (points.length === 2) {
      const res = { geoType: 'GeometryCollection', geoData: cyy }
      return res
    }

    // let l=3// Math.floor(l/100)+1
    const l = plot.wholeDistance(points) / (distance * 5) // 个间距长度画一组圆
    // console.log(l)
    let n = null
    let n1
    // let cl
    // let cl1
    let mx, my
    for (let i = 1; i < l; i++) {
      n = Math.floor(bLine01.data.length / l * i) - 5 // - distance// line.length() - 15
      if (n <= 0) n = 5
      n1 = Math.floor(bLine01.data.length / l * i) + 5 // + distance// line.length()15
      if (n1 > 90) {
        n1 = 90
        n = 80
      }
      // console.log(bLine01.data.length,n, n1)
      // console.log(bLine01.data.length,n, n1)
      mx = (bLine01.data[n][0] + Pnew[n][0]) / 2 // (P[n].x+Pnew[n].x)/2
      my = (bLine01.data[n][1] + Pnew[n][1]) / 2 // (P[n].y+Pnew[n].y)
      // cl=group.circle(Math.abs(dlt[n])).fill('none').stroke({color:'red', width:5}).center(mx,my)
      // mx.my是圆心，dlt[n]是直径
      // console.log(dlt)
      cyy.push({ type: 'Circle', data: [[mx, my], [mx, my + dlt[n] / 2]] }) // dlt[n] / 2

      console.log(n1, Pnew[n1])
      mx = (bLine01.data[n1][0] + Pnew[n1][0]) / 2 // mx=(P[n1].x+Pnew[n1].x)/2
      my = (bLine01.data[n1][1] + Pnew[n1][1]) / 2 // my=(P[n1].y+Pnew[n1].y)/2
      // cl=group.circle(Math.abs(dlt[n1])).fill('none').stroke({color:'red', width:5}).center(mx,my)
      cyy.push({ type: 'Circle', data: [[mx, my], [mx, my + dlt[n] / 2]] })
    }
    // 返回军标数据
    const res = { geoType: 'GeometryCollection', geoData: cyy }
    return res
  }
}
// 两控制点时加一个控制点
plot.getCyyLine = function (points, dl = null) {
  let bLine01 = null
  let bLine02 = null
  const cyy = []
  const distance = plot.CalLengthOfTwoPoints(points[0], points[1]) * plot.headHeightFactor // 获取箭头长度（前两点）
  // 动态获取间距值
  if (!dl) {
    // 如果两条线的间距未指定，取箭头的宽度做间距
    // dl = -distance * plot.headWidthFactor // 获取箭头宽度
    dl = distance * plot.headWidthFactor // 获取箭头宽度
  }
  // 滚轮位置确定
  const numPnts = points.length
  if (points[numPnts - 1][0] - points[numPnts - 2][0] > 0) {
    dl = -dl
  }

  if (points.length > 1) {
    // 箭头部分
    const iArrow = plot.getArrowHeadPointsForSLine2(points, plot.headHeightFactor, plot.headWidthFactor, plot.neckHeightFactor)
    let midPnt
    // 计算贝赛尔曲线；points为传入的贝塞尔控制点。
    if (points.length === 2) {
      midPnt = [(points[0][0] + points[1][0]) / 2, (points[0][1] + points[1][1]) / 2]
      // bLine01 = points // { type: 'LineString', data: list }
      bLine01 = plot.getBezierPoints2([points[0], midPnt, points[1]])
    } else {
      bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    }
    // bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    const P = JSON.parse(JSON.stringify(bLine01.data))
    cyy.push(iArrow)
    cyy.push(bLine01)
    // 创建平行线数组
    const Pnew = [] // new Array(Math.floor(P.length+1))
    const dlt = new Array(Math.floor(P.length + 1)) // 两条线间距-绘制圆时的直径
    // var P1={x:2*(points[1].x-points[0].x),y:2*(points[1].y-points[0].y)}
    const P1 = { x: 2 * (points[1][0] - points[0][0]), y: 2 * (points[1][1] - points[0][1]) }
    // 两条线的距离
    // Pnew[0]={x:points[0].x-P1.y*dl/Math.sqrt(Math.pow(P1.x,2)+Math.pow(P1.y,2)),
    //     y:points[0].y+P1.x*dl/Math.sqrt(Math.pow(P1.x,2)+Math.pow(P1.y,2))}
    // Pnew[0]={x:points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x,2) + Math.pow(P1.y,2)),
    // y:points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x,2) + Math.pow(P1.y,2))}
    Pnew[0] = [points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2)),
      points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2))]
    // console.log('-----:',Pnew[0])
    // console.log(points[0][0],P1.y * dl,Math.pow(P1.x,2),Math.pow(P1.y,2))
    // P[0]=points[0]
    // P[1]=line.pointAt(1)
    let x12 // 点1和点2的x距离
    let y12 // 点1和点2的y距离
    let x01 // 点1和点0的x距离
    let y01 // 点1和点0的y距离
    let a
    let b
    let k
    let r
    // var line1
    for (let i = 1; i < P.length - 1; i++) {
      // if(i==Math.floor(line.length()-1)){P[i+1]=line.pointAt(line.length())}else{
      // P[i+1]=line.pointAt(i+1)
      x12 = P[i + 1][0] - P[i][0]
      y12 = P[i + 1][1] - P[i][1]
      x01 = P[i][0] - P[i - 1][0]
      y01 = P[i][1] - P[i - 1][1]
      if (x12 === 0) {
        a = Math.PI / 2
        if (y12 < 0) { a = -a }
      } else {
        a = Math.atan2(y12, x12)
      }
      if (x01 === 0) {
        b = Math.PI / 2
        if (y01 < 0) { b = -b }
      } else {
        b = Math.atan2(y01, x01)
      }
      k = (b - a - Math.PI) / 2
      r = a + k
      dlt[i] = dl / Math.sin(k)
      // Pnew[i]={x:P[i][0]+dlt[i]*Math.cos(r),y:P[i][1]+dlt[i]*Math.sin(r)}
      // Pnew[i]=[P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      const newPnt = [P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      if (newPnt) {
        Pnew.push(newPnt)
      }
      // 改成画直线line1=group.line(Pnew[i-1].x,Pnew[i-1].y,Pnew[i].x,Pnew[i].y).stroke({color:'black', width:2})
      // console.log(x12,y12,x01,y01,a,b,k,r)
      // console.log(P[i][0],dlt[i],Math.cos(r),P[i][1],Math.sin(r))
      // console.log(Pnew)
    }
    // Pnew.splice(100,2)
    bLine02 = { type: 'LineString', data: Pnew }

    cyy.push(bLine02)
    // for(let x=0; x<Pnew.length; x++){
    //   console.log('out:',x,Pnew[x])
    // }
    console.log(bLine01, bLine02)
    // let res = {geoType: 'GeometryCollection', geoData: cyy}
    // return res
    // 绘制跟随箭头到此结束

    // let l=3// Math.floor(l/100)+1
    const l = plot.wholeDistance(points) / (distance * 4) // 个间距长度画一组圆
    // console.log(l)
    let n = null
    let n1
    // let cl
    // let cl1
    let mx, my
    for (let i = 1; i < l; i++) {
      n = Math.floor(bLine01.data.length / l * i) - 4 // - distance// line.length() - 15
      if (n <= 0) n = 4
      n1 = Math.floor(bLine01.data.length / l * i) + 4 // + distance// line.length()15
      if (n1 > 90) {
        n1 = 90
        n = 82
      }
      // console.log(bLine01.data.length,n, n1)
      // console.log(bLine01.data.length,n, n1)
      mx = (bLine01.data[n][0] + Pnew[n][0]) / 2 // (P[n].x+Pnew[n].x)/2
      my = (bLine01.data[n][1] + Pnew[n][1]) / 2 // (P[n].y+Pnew[n].y)
      // cl=group.circle(Math.abs(dlt[n])).fill('none').stroke({color:'red', width:5}).center(mx,my)
      // mx.my是圆心，dlt[n]是直径
      // console.log(dlt)
      cyy.push({ type: 'Circle', data: [[mx, my], [mx, my + dlt[n] / 2]] }) // dlt[n] / 2

      console.log(n1, Pnew[n1])
      mx = (bLine01.data[n1][0] + Pnew[n1][0]) / 2 // mx=(P[n1].x+Pnew[n1].x)/2
      my = (bLine01.data[n1][1] + Pnew[n1][1]) / 2 // my=(P[n1].y+Pnew[n1].y)/2
      // cl=group.circle(Math.abs(dlt[n1])).fill('none').stroke({color:'red', width:5}).center(mx,my)
      cyy.push({ type: 'Circle', data: [[mx, my], [mx, my + dlt[n] / 2]] })
    }
    // 返回军标数据
    const res = { geoType: 'GeometryCollection', geoData: cyy }
    return res
  }
}

// 摩托化行进
plot.getMotorLine = function (points, dl = null) {
  let bLine01 = null
  const bLine02 = null
  const cyy = []
  const distance = plot.CalLengthOfTwoPoints(points[0], points[1]) * plot.headHeightFactor // 获取箭头长度（前两点）
  // 动态获取间距值
  if (!dl) {
    // 如果两条线的间距未指定，取箭头的宽度做间距
    // dl = -distance * plot.headWidthFactor // 获取箭头宽度
    dl = distance * plot.headWidthFactor // 获取箭头宽度
  }
  // 滚轮位置确定
  const numPnts = points.length
  if (points[numPnts - 1][0] - points[numPnts - 2][0] > 0) {
    dl = -dl
  }

  if (points.length > 1) {
    // 箭头部分
    const iArrow = plot.getArrowHeadPointsForSLine2(points, plot.headHeightFactor, plot.headWidthFactor, plot.neckHeightFactor)
    let midPnt
    // 计算贝赛尔曲线；points为传入的贝塞尔控制点。
    if (points.length === 2) {
      midPnt = [(points[0][0] + points[1][0]) / 2, (points[0][1] + points[1][1]) / 2]
      // bLine01 = points // { type: 'LineString', data: list }
      bLine01 = plot.getBezierPoints2([points[0], midPnt, points[1]])
    } else {
      bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    }
    // bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    const P = JSON.parse(JSON.stringify(bLine01.data))
    cyy.push(iArrow)
    cyy.push(bLine01)
    // 创建平行线数组
    const Pnew = [] // new Array(Math.floor(P.length+1))
    const dlt = new Array(Math.floor(P.length + 1)) // 两条线间距-绘制圆时的直径
    // var P1={x:2*(points[1].x-points[0].x),y:2*(points[1].y-points[0].y)}
    const P1 = { x: 2 * (points[1][0] - points[0][0]), y: 2 * (points[1][1] - points[0][1]) }
    // 两条线的距离
    // Pnew[0]={x:points[0].x-P1.y*dl/Math.sqrt(Math.pow(P1.x,2)+Math.pow(P1.y,2)),
    //     y:points[0].y+P1.x*dl/Math.sqrt(Math.pow(P1.x,2)+Math.pow(P1.y,2))}
    // Pnew[0]={x:points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x,2) + Math.pow(P1.y,2)),
    // y:points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x,2) + Math.pow(P1.y,2))}
    Pnew[0] = [points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2)),
      points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2))]
    // console.log('-----:',Pnew[0])
    // console.log(points[0][0],P1.y * dl,Math.pow(P1.x,2),Math.pow(P1.y,2))
    // P[0]=points[0]
    // P[1]=line.pointAt(1)
    let x12 // 点1和点2的x距离
    let y12 // 点1和点2的y距离
    let x01 // 点1和点0的x距离
    let y01 // 点1和点0的y距离
    let a
    let b
    let k
    let r
    // var line1
    for (let i = 1; i < P.length - 1; i++) {
      // if(i==Math.floor(line.length()-1)){P[i+1]=line.pointAt(line.length())}else{
      // P[i+1]=line.pointAt(i+1)
      x12 = P[i + 1][0] - P[i][0]
      y12 = P[i + 1][1] - P[i][1]
      x01 = P[i][0] - P[i - 1][0]
      y01 = P[i][1] - P[i - 1][1]
      if (x12 === 0) {
        a = Math.PI / 2
        if (y12 < 0) { a = -a }
      } else {
        a = Math.atan2(y12, x12)
      }
      if (x01 === 0) {
        b = Math.PI / 2
        if (y01 < 0) { b = -b }
      } else {
        b = Math.atan2(y01, x01)
      }
      k = (b - a - Math.PI) / 2
      r = a + k
      dlt[i] = dl / Math.sin(k)
      // Pnew[i]={x:P[i][0]+dlt[i]*Math.cos(r),y:P[i][1]+dlt[i]*Math.sin(r)}
      // Pnew[i]=[P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      const newPnt = [P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      if (newPnt) {
        Pnew.push(newPnt)
      }
    }

    // 添加圆轮
    const l = plot.wholeDistance(points) / (distance * 4) // 个间距长度画一组圆
    // console.log(l)
    let n = null
    let n1
    // let cl
    // let cl1
    let mx, my
    for (let i = 1; i < l; i++) {
      n = Math.floor(bLine01.data.length / l * i) - 4 // - distance// line.length() - 15
      if (n <= 0) n = 4
      n1 = Math.floor(bLine01.data.length / l * i) + 4 // + distance// line.length()15
      if (n1 > 90) {
        n1 = 90
        n = 82
      }
      // console.log(bLine01.data.length,n, n1)
      // console.log(bLine01.data.length,n, n1)
      mx = (bLine01.data[n][0] + Pnew[n][0]) / 2 // (P[n].x+Pnew[n].x)/2
      my = (bLine01.data[n][1] + Pnew[n][1]) / 2 // (P[n].y+Pnew[n].y)
      // cl=group.circle(Math.abs(dlt[n])).fill('none').stroke({color:'red', width:5}).center(mx,my)
      // mx.my是圆心，dlt[n]是直径
      // console.log(dlt)
      cyy.push({ type: 'Circle', data: [[mx, my], [mx, my + dlt[n] / 2]] }) // dlt[n] / 2

      // console.log(n1, Pnew[n1])
      mx = (bLine01.data[n1][0] + Pnew[n1][0]) / 2 // mx=(P[n1].x+Pnew[n1].x)/2
      my = (bLine01.data[n1][1] + Pnew[n1][1]) / 2 // my=(P[n1].y+Pnew[n1].y)/2
      // cl=group.circle(Math.abs(dlt[n1])).fill('none').stroke({color:'red', width:5}).center(mx,my)
      cyy.push({ type: 'Circle', data: [[mx, my], [mx, my + dlt[n] / 2]] })
    }
    // 返回军标数据
    const res = { geoType: 'GeometryCollection', geoData: cyy }
    return res
  }
}

// 伴随线
plot.getFollowLine = function (points, dl = null) {
  let bLine01 = null
  let bLine02 = null
  const cyy = []
  const distance = plot.CalLengthOfTwoPoints(points[0], points[1]) * plot.headHeightFactor // 获取箭头长度（前两点）
  // 动态获取间距值
  if (!dl) {
    // 如果两条线的间距未指定，取箭头的宽度做间距
    dl = distance * plot.neckWidthFactor / 2 // 获取箭头宽度
  }
  // 滚轮位置确定
  const numPnts = points.length
  if (points[numPnts - 1][0] - points[numPnts - 2][0] < 0) {
    dl = -dl
  }

  if (points.length > 1) {
    // 箭头部分
    const iArrow = plot.getArrowHeadPointsForSLine2(points, plot.headHeightFactor, plot.headWidthFactor, plot.neckHeightFactor)
    let midPnt
    // 计算贝赛尔曲线；points为传入的贝塞尔控制点。
    if (points.length === 2) {
      midPnt = [(points[0][0] + points[1][0]) / 2, (points[0][1] + points[1][1]) / 2]
      // bLine01 = points // { type: 'LineString', data: list }
      bLine01 = plot.getBezierPoints2([points[0], midPnt, points[1]])
    } else {
      bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    }
    // bLine01 = plot.getBezierPoints2(points) // { type: 'LineString', data: list }
    const P = JSON.parse(JSON.stringify(bLine01.data))
    cyy.push(iArrow)
    cyy.push(bLine01)
    // 创建平行线数组
    const Pnew = [] // new Array(Math.floor(P.length+1))
    const dlt = new Array(Math.floor(P.length + 1)) // 两条线间距-绘制圆时的直径
    // var P1={x:2*(points[1].x-points[0].x),y:2*(points[1].y-points[0].y)}
    const P1 = { x: 2 * (points[1][0] - points[0][0]), y: 2 * (points[1][1] - points[0][1]) }
    // 两条线的距离
    Pnew[0] = [points[0][0] - P1.y * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2)),
      points[0][1] + P1.x * dl / Math.sqrt(Math.pow(P1.x, 2) + Math.pow(P1.y, 2))]
    let x12 // 点1和点2的x距离
    let y12 // 点1和点2的y距离
    let x01 // 点1和点0的x距离
    let y01 // 点1和点0的y距离
    let a
    let b
    let k
    let r
    // var line1
    for (let i = 1; i < P.length - 1; i++) {
      x12 = P[i + 1][0] - P[i][0]
      y12 = P[i + 1][1] - P[i][1]
      x01 = P[i][0] - P[i - 1][0]
      y01 = P[i][1] - P[i - 1][1]
      if (x12 === 0) {
        a = Math.PI / 2
        if (y12 < 0) { a = -a }
      } else {
        a = Math.atan2(y12, x12)
      }
      if (x01 === 0) {
        b = Math.PI / 2
        if (y01 < 0) { b = -b }
      } else {
        b = Math.atan2(y01, x01)
      }
      k = (b - a - Math.PI) / 2
      r = a + k
      dlt[i] = dl / Math.sin(k)
      // Pnew[i]={x:P[i][0]+dlt[i]*Math.cos(r),y:P[i][1]+dlt[i]*Math.sin(r)}
      // Pnew[i]=[P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      const newPnt = [P[i][0] + dlt[i] * Math.cos(r), P[i][1] + dlt[i] * Math.sin(r)]
      if (newPnt) {
        Pnew.push(newPnt)
      }
    }
    // 伴随线超过了箭头，调整下；
    Pnew.splice(90, 15)
    bLine02 = { type: 'LineString', data: Pnew }
    cyy.push(bLine02)
    console.log(bLine01, bLine02)
    const res = { geoType: 'GeometryCollection', geoData: cyy }
    return res
  }
}

// // 牵引线（三角形-polgyon）放到plottinglayer中了
// plot.getTriangle = function (points) {
//   let cpNum = points.length

// }

// 获取方法
plot.getFunc = function (funcName) {
  const fn = eval('plot.' + funcName)
  if (typeof fn === 'function') {
    return fn
  } else {
    return null
  }
}

export {
  plot
}
